/*
* @Author: Yejing
* @Date: 2023-06-14 09:20:30
* @LastEditors: Yejing
* @LastEditTime: 2023-07-21 09:47:57
* @Description: 任务列表/主播带货任务列表
*/
<template>
	<view class="bathor-orders-page">
		<c-layout>
			<c-navigation-bar :title="taskTitle" slot="head" @backEvent="toback()"></c-navigation-bar>
			<view slot="head" class="search">
				<u-input maxlength="12" type="text" v-model="input.value" :clearable="false" :placeholder="input.placeholder">
				</u-input>
				<view class="input-search-button">
					<u-icon name="search" size="40" color="#fff" @click="searchEvent"></u-icon>
				</view>
			</view>

			<view class="container-box">
				<!-- 搜索分类 -->
				<searchType :searchType='searchType' @noticeHandle="noticeHandle">
					<template v-for="(swiper,index) in searchType.info" :slot='index'>
						<swiper-item @catchtouchmove="stopTouchMove" :key="index">
							<scroll-view class="main-info" scroll-y="true" style="height: 100%" @scrolltolower="getNewsData">
								<view v-if="index==0">
									<type :type="followUrlData.type" :cardData="taskList[index]"></type>
								</view>
								<view v-if="index==1">
									<type :type="followUrlData.type" :cardData="taskList[index]"></type>
								</view>
								<view v-if="index==2">
									<type :type="followUrlData.type" :cardData="taskList[index]"></type>
								</view>
								<view v-if="index==3">
									<type :type="followUrlData.type" :cardData="taskList[index]"></type>
								</view>
								<view v-if="index==4">
									<type :type="followUrlData.type" :cardData="taskList[index]"></type>
								</view>
								<view v-if="index==5">
									<type :type="followUrlData.type" :cardData="taskList[index]"></type>
								</view>
								<view v-if="index==6">
									<type :type="followUrlData.type" :cardData="taskList[index]"></type>
								</view>
							</scroll-view>
						</swiper-item>
					</template>
				</searchType>
			</view>
		</c-layout>
	</view>
</template>

<script>
	import type from './type.vue'

	export default {
		components: {
			type
		},
		data() {
			return {
				input: {
					value: '',
					placeholder: this.$t('home.placeholder')
				},
				postTaskHallObj: {
					pageSize: 9999,
					pageNum: 1,
				},
				searchType: {
					tabList: [this.$t('storeManagement.all'), this.$t('orderDetails.UnderReview'), this.$t(
						'orderDetails.Unapprove'), this.$t('product.InProgress'), this.$t('orderDetails.Completed')],
					info: [{
						data: []
					}, {
						data: []
					}, {
						data: []
					}, {
						data: []
					}, {
						data: []
					},
					{
						data: []
					}],
				},
				newTaskList: [],
				total: 0,
				taskTitle: this.$t('storeManagement.batchOrders'),
				followUrlData: {}
			};
		},
		onLoad(val) {
			this.followUrlData = val
			if (this.followUrlData.type == 'anchor') {
				this.taskTitle = this.$t('storeManagement.batchOrders')
				this.searchType.tabList = [this.$t('storeManagement.all'), this.$t('product.notApply'), this.$t(
					'product.NotProgress'), this.$t('product.InProgress'), this.$t('product.unbalanced'), this.$t(
					'product.balanced')]
				this.getTaskHallList(1, this.postTaskHallObj)
			} else {
				//获取大厅任务列表
				this.followUrlData.type = 'shopxq'
				this.getTaskHallList(null, this.postTaskHallObj)
			}
		},
		computed: {
			taskList() {
				const list = []
				if (this.followUrlData.type == 'anchor') {
					// 状态（0：未进行 1：进行中 2：进行完待结算 3：已完成结算）
					const arr = ['4', '0', '1', '2', '3']
					// 遍历类型列表按顺序插入不同类型
					arr.forEach(ele => {
						list.push(this.newTaskList.filter(f => f.status == ele))
					})
					return [this.newTaskList, ...list]
				} else {
					// 类型列表
					// 状态（0：审核中 1：未通过审核 2：进行中 5:已结束 ）
					const arr = ['0', '1', '2', '5']
					// 遍历类型列表按顺序插入不同类型
					arr.forEach(ele => {
						list.push(this.newTaskList.filter(f => f.status == ele))
					})
					return [this.newTaskList, ...list]
				}
			}


		},
		methods: {
			//搜索
			searchEvent() {
				this.postTaskHallObj.name = this.input.value
				this.newTaskList = []
				if (this.followUrlData.type == 'anchor') {
					this.getTaskHallList(1, this.postTaskHallObj)
				} else {
					this.getTaskHallList(null, this.postTaskHallObj)
				}
			},
			toback(){
				let pages = getCurrentPages() // 获取栈实例
				let page = pages[pages.length - 1] // 获取当前页面的数据，包含页面路由
				let prevPage = pages[pages.length - 2] // 获取上个页面的数据，包含页面
				console.log(prevPage.route)
				if (prevPage.route == 'pages/anchorConsole/anchorConsole') {
					uni.reLaunch({
						url:'/pages/anchorConsole/anchorConsole'
					})
				} else {
					uni.reLaunch({
						url:'/pages/storyType/storeManagement'
					})
				}
			},
			//获取大厅任务列表
			getTaskHallList(type, postTaskHallObj) {
				let url = type ? '/app/anchor/sell/task/anchorSellTaskList' : '/app/shop/sell/task/sellTaskPage'
				this.$u.post(url, postTaskHallObj).then(res => {
					if (res.data.records.length > 0) {
						this.newTaskList = res.data.records
					} else {
						this.newTaskList = []
					}
					this.total = res.data.total
				})
			},
			//冒泡事件避免影响底层滚动
			stopTouchMove() {
				return false;
			},
			//点击或者滑动
			noticeHandle(e) {},
			//分页
			getNewsData() {
				if (this.newTaskList.length == this.total) {
					return
				}
				this.postTaskHallObj.pageNum += 1
				if (this.followUrlData.type == 'anchor') {
					this.getTaskHallList(1, this.postTaskHallObj)
				} else {
					this.getTaskHallList(null, this.postTaskHallObj)
				}
			},
		},
	}
</script>

<style lang="scss">
	.bathor-orders-page {
		.search {
			height: 110rpx;
			border-radius: 24rpx;
			backdrop-filter: blur(10px);
			display: flex;
			align-items: center;
			padding: 0 18rpx;
			margin: 16px 16px 16px 16px;
			background: rgb(246, 247, 251);

			.input-search-button {
				width: 76rpx;
				height: 76rpx;
				background: #2934D0;
				border-radius: 20rpx;
				text-align: center;
				line-height: 85rpx;
			}
		}

		.container-box {
			padding-top: 0;

			/deep/ .search-type {
				height: calc(100vh - 380rpx);
			}
		}
	}
</style>